// app组件所有的子组件在此渲染
// 引入类组件,Component(props, context, updater)
import React, { Component } from 'react'
// 引入Admin类组件
import Admin from '@pages/Admin'
import Login from '@pages/Login'
import NotFound from '@pages/NotFound'
// 引入switch组件，路由组件，重定向组件
import { Switch, Route, Redirect } from 'react-router-dom'
// console.log(Component);
// console.log(Admin);
// console.log(Switch);
import { isLogin } from '@/utils'
export default class App extends Component {
  render() {
    return (
      // 只能匹配一个,包裹route组件
      <Switch>
        <Route path="/admin" render={
          (routeProps) => {
            if(isLogin()) {
              return <Admin {...routeProps}/>
            }else{
              return <Redirect to="/login"/>
            }
          }
        }/>
        <Route path="/login" component={Login}/>
        <Route path="/404" component={NotFound}/>
        {/* exact精准匹配，地址栏输入/匹配到admin路由 */}
        <Redirect to="/admin" from="/" exact/>
        <Redirect to="/404"/>
      </Switch>
    )
  }
}
